unit Demo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Math, StdCtrls;

type
  TfrmCanvasDraw = class(TForm)
    btnAngleTest: TButton;
    edt1: TEdit;
    edt2: TEdit;
    edt3: TEdit;
    edt4: TEdit;
    edt5: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    procedure btnAngleTestClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCanvasDraw: TfrmCanvasDraw;

implementation

{$R *.dfm}

procedure TfrmCanvasDraw.btnAngleTestClick(Sender: TObject);
var
  X0, Y0, Radius: Integer;
  StartAngle, SweepAngle: Extended;
  Sin, Cos: Extended;
  X1, Y1, X2, Y2: Integer;
begin
  X0:= StrToInt(edt1.Text);
  Y0:= StrToInt(edt2.Text);
  Radius:= StrToInt(edt3.Text);
  StartAngle:= StrToFloat(edt4.Text);
  SweepAngle:= StrToFloat(edt5.Text);

  Repaint;
  Canvas.Pen.Color := clDefault;
  Canvas.MoveTo(X0 - Radius, Y0 - Radius); // Bounding box of the circle
  Canvas.LineTo(X0 + Radius, Y0 - Radius);
  Canvas.LineTo(X0 + Radius, Y0 + Radius);
  Canvas.LineTo(X0 - Radius, Y0 + Radius);
  Canvas.LineTo(X0 - Radius, Y0 - Radius);
  Canvas.MoveTo(X0, Y0);
  SinCos(((StartAngle+SweepAngle)*2*Pi)/360, Sin, Cos);  // Angle has to be radians
  X1 := X0 + Round(Radius*Cos);
  Y1 := Y0 - Round(Radius*Sin);
  Canvas.LineTo(X1, Y1); // Sweep is relative to Start
  Canvas.MoveTo(X0, Y0);
  SinCos((StartAngle*2*Pi)/360, Sin, Cos);
  X2 := X0 + Round(Radius*Cos);
  Y2 := Y0 - Round(Radius*Sin);
  Canvas.LineTo(X2, Y2);
  Canvas.Pen.Color := clRed;
  Canvas.Arc(X0 - Radius, Y0 - Radius, X0 + Radius, Y0 + Radius, X2, Y2, X1, Y1);
  Canvas.LineTo(300, 300);  // Show where AngleArc left the current position.
  Canvas.Brush.Color := clGreen;
  Canvas.Pie(X0 - Radius, Y0 - Radius, X0 + Radius, Y0 + Radius, X2, Y2, X1, Y1);
end;

end.
